package sort;

import java.util.ArrayList;
import java.util.List;

@SuppressWarnings({"all"})
public class Test_4 {
    public static void main(String[] args) {
        ArrayList arrayList = new ArrayList<Animal>();
        arrayList.add(0,new Cat("mack",3));
     arrayList.add(1,new Dog("mack",3));
    arrayList.add(2,new Cat("小黄",3));
       arrayList.add(3,new Dog("大毛",3));

        for(Object tem:arrayList){
            System.out.println(tem);
        }

        //ArrayList中的index，必须为有序,即从0~n;
    }
}

class Animal{
    private String name;
    private int age;

    @Override
    public String toString() {
        return "Animal{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void eat(){
        System.out.println("动物吃东西");
    }
}

class employee{
    private String name;
    private int age;
    public void work(){
        System.out.println("牛马上班");
    }
}

class Cat extends Animal{
  public void eat(){
      System.out.println("猫吃老鼠");
  }

    public Cat(String name, int age) {
        super(name, age);
    }
}

class Dog extends Animal{
    @Override
    public void eat() {
        System.out.println("狗吃辣条");
    }

    public Dog(String name, int age) {
        super(name, age);
    }
}